import java.util.Arrays;

public class Test {
    public static int[] copy(int[] arr1, int[] arr2) {
        arr2 = new int[arr1.length];
        for (int i = 0; i < arr1.length; i++) {
            arr2[i] = arr1[i];
        }
        return arr2;
    }
 /*   public static int[] arr() {
        int[] arr = {1, 2, 3, 4, 5};
        return arr;
    }*/

    public static String myToString(int[] tmp) {
        if (tmp == null) {
            return "null";
        }
        String ret = "[";
        for (int i = 0; i < tmp.length; i++) {
            ret += tmp[i];
            if (i != tmp.length - 1) {
                ret += ",";
            }
        }
        ret += "]";
        return ret;
    }

    public static double avg(int[] arr) {//求数组中的平均数
        double sum = 0.0;
        for (double x : arr) {
            sum += x;
        }
        return sum / arr.length;
    }

    public static int find(int[] arr, int key) {//查找数组中的元素并返回下标（顺序查找）
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == key) {
                return i;
            }

        }
        return -1;
    }

    public static int binarySearch(int[] arr, int key) {//二分查找
        int left = 0;
        int right = arr.length - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (arr[mid] < key) {
                left = mid + 1;
            } else if (arr[mid] > key) {
                right = mid - 1;
            } else return mid;

        }
        return -1;
    }
    public static int[] find1(int[] arr,int target){
        int[] ret=new int[2];
        for (int i = 0; i < arr.length; i++) {
            for (int j = i+1; j <arr.length ; j++) {
                if(arr[i]+arr[j]==target){
                    ret[0]=i;
                    ret[1]=j;
                    return ret;
                }
            }
        }
        return ret;
    }

    public static void reverse(int[] arr) {//数组的逆序
        int left = 0;
        int right = arr.length - 1;
        while (left < right) {
            int tmp = arr[left];
            arr[left] = arr[right];
            arr[right] = tmp;
            left++;
            right--;
        }

    }
    public static int fun2(int[] arr){
        //找到数组中出现一次的数
        int ret=arr[0];
        for (int i = 0; i < arr.length; i++) {
            ret=ret^arr[i];
        }
        return ret;
    }

    public static void bubbleSort(int[] arr) {
        //冒泡排序
        for (int i = 0; i < arr.length - 1; i++) {
            boolean flag = false;
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int tmp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = tmp;
                    flag = true;
                }
            }
            if (flag == false) {
                return;
            }
        }
    }

    public static void print(int[][] arr) {
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
    public static void fun1(int[] arr){
        //让数组的奇数排在偶数的前面，不考虑顺序
        int i=0;
        int j=arr.length-1;
        while(i<j){
            while(i<j&&arr[i]%2!=0){
                i++;
            }
            while(i<j&&arr[j]%2==0){
                j--;
            }
            int tmp=arr[i];
            arr[i]=arr[j];
            arr[j]=tmp;
        }
    }

    public static void main(String[] args) {
        int[] arr={1,2,3,2,1};
        int ret=fun2(arr);
        System.out.println(ret);
    }
    public static void main9(String[] args) {
        //不规则数组(列可以省略)
        int[][] arr1 = new int[2][];
        arr1[0]=new int[3];
        arr1[1]=new int[4];
        System.out.println(Arrays.toString(arr1[0]));
        System.out.println(Arrays.toString(arr1[1]));
        int[] arr2={1,2,3,4,5,6,7,8,9};
        //fun1(arr2);
        int[] ret=new int[2];
              ret= find1(arr2,10);
        System.out.println(Arrays.toString(ret));

        //System.out.println(Arrays.toString(arr2));

    }

    public static void main8(String[] args) {
       /* int[][] arr = new int[2][3];
        print(arr);*/
        int[][] arr1 = new int[][]{{1, 2, 3}, {4, 5, 6}};
        for (int[] array : arr1) {
            for (int x : array) {
                System.out.print(x + " ");
            }
            System.out.println();
        }

      /*  System.out.println(Arrays.deepToString(arr1));
        System.out.println(Arrays.toString(arr1[0]));
        System.out.println(Arrays.toString(arr1[1]));*/

        int[][] arr2 = {{1, 2, 3}, {4, 5, 6}};
    }

    public static void main7(String[] args) {
        int[] arr = {11, 22, 3, 44, 55, 6, 77, 88, 9};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));

    }

    public static void main6(String[] args) {
        int[] arr1 = {11, 22, 33, 44, 5, 6, 7, 8, 9};
        Arrays.sort(arr1);
        System.out.println(Arrays.toString(arr1));
        //System.out.println(binarySearch(arr1, 9));
        reverse(arr1);
        System.out.println(Arrays.toString(arr1));
        Arrays.fill(arr1, 1, 4, 2);
        System.out.println(Arrays.toString(arr1));

       /* double  ret=avg(arr1);
        System.out.println(ret);
        System.out.println(find(arr1,0));*/

    }

    public static void main5(String[] args) {
        int[] arr1 = {1, 2, 3, 4};
        int[] arr2 = new int[arr1.length];
        System.arraycopy(arr1, 0, arr2, 0, arr1.length);
        System.out.println(Arrays.toString(arr2));
        int[] arr3 = Arrays.copyOfRange(arr1, 1, 3);//[2,3)
        System.out.println(Arrays.toString(arr3));
        int[] arr4 = arr1.clone();
        System.out.println(Arrays.toString(arr4));
        int[] arr5 = Arrays.copyOf(arr1, arr1.length);
        System.out.println(Arrays.toString(arr5));

    }

    public static void main4(String[] args) {
        int[] arr = null;
        String ret = myToString(arr);
        System.out.println(ret);
        int[] arr1 = {1, 2, 3, 4};
        int[] arr2 = null;
        arr2 = copy(arr1, arr2);
        System.out.println(Arrays.toString(arr2));
    }

    public static void main3(String[] args) {
        int[] arr = {1, 2, 3, 4};
        int[] arr1;
        arr1 = new int[]{1, 2, 3, 4};
        String ret = Arrays.toString(arr);
        System.out.println(ret);
    }

 /*   public static void main2(String[] args) {
        int[] ret = arr();
        System.out.println(Arrays.toString(ret));
    }*/

    public static void main1(String[] args) {
        int[] arr = null;
        int[] arr0 = {1, 2, 3};//静态初始化
        int[] arr2 = new int[]{1, 2, 3, 4};//动态初始化
        int[] arr3 = new int[10];
        int len = arr.length;
        // System.out.println(len);
        for (int x : arr) {
            System.out.print(x + " ");
        }
        System.out.println();
        for (int i = 0; i < len; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        String ret = Arrays.toString(arr);
        System.out.println(ret);
    }
}
